package org.rishi.framework.db;

import java.io.Serializable;
import java.util.Map;
import java.util.TreeMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author MHT E-mail:mht1984@126.com
 * @version 创建时间：2010-8-31 下午05:01:09
 *
 */
class ConfigParser implements Serializable {

    private static final String $version = "v1.0 (SVN $Revision:  $)";

    private final static Logger logger = LoggerFactory.getLogger(ConfigParser.class);

    private static final long serialVersionUID = 3246587199368951463L;

    static final Map NAMED_QUERY_MAPPING = new TreeMap();

    static final Map COL_MAPPING = new TreeMap();

    static String datePattern = "yyyy-MM-dd";

    static String tsPattern = "yyyy-MM-dd HH:mm:ss.SSS";

    static {
        logger.info("Loading " + ConfigParser.class);
        logger.info("Loading " + YAMLConfigParser.class);
    }

    /**
     * Returns SQL statement as configured in db.xml.
     *
     * @param namedQuery - named query
     * @return String - SQL statement
     */
    static String getQuery(String namedQuery) {

        String q = (String) ConfigParser.NAMED_QUERY_MAPPING.get(namedQuery);
        if (q == null)
            return "";
        else
            return q;

    }

    ConfigParser() {

        String vendor = (System.getProperty("java.vendor") == null) ? "--" : System.getProperty("java.vendor");
        logger.info("rishi initializing : JVM " + vendor + " - " + System.getProperty("java.version"));

        try {

            new YAMLConfigParser().init();
            // boolean parsed = false;

        } catch (Throwable e) {

            e.printStackTrace();
            logger.warn("rishi YAML config file Error!");
            logger.error(e.getMessage());

        }

        logger.info("rishi Framework " + $version + " initialization complete");

    }

}
